import { IsNotEmpty, IsString, IsOptional, IsObject, IsUrl, MaxLength } from 'class-validator';
import { Transform } from 'class-transformer';

export class TrackPageviewDto {
  @IsNotEmpty()
  @IsString()
  @MaxLength(64)
  trackingId: string;

  @IsNotEmpty()
  @IsString()
  @IsUrl({ require_tld: false })
  url: string;

  @IsOptional()
  @IsString()
  @MaxLength(255)
  title?: string;

  @IsOptional()
  @IsString()
  @MaxLength(512)
  referrer?: string;

  @IsOptional()
  @IsString()
  @MaxLength(64)
  sessionId?: string;

  @IsOptional()
  @IsObject()
  @Transform(({ value }) => {
    try {
      return typeof value === 'string' ? JSON.parse(value) : value;
    } catch {
      return {};
    }
  })
  customData?: Record<string, any>;
} 